<template>
  <div>
    <h1>reset接口测试</h1>
    <button @click="testPost">post 提交数据</button>
    <button @click="testGet">get 请求</button>
    <button @click="testDel">delete 删除</button>
    <button @click="testPut">put 更新</button>
  </div>
</template>

<script>
import axios from "axios";
export default {
  /* 
    post 
    get
    put 
    delete
    */
  methods: {
    //   http://localhost:3000/posts  可以做post请求
    testPost() {
      axios
        .post("http://localhost:3000/posts", {
          name: "hanhan",
          info: "我心飞扬！！！",
        })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //  http://localhost:3000/posts  可以做get请求
    testGet() {
      axios
        .get("http://localhost:3000/posts", {
          params: {
            id: 1,
          },
        })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //  http://localhost:3000/posts  可以做delete请求
    testDel() {
      axios
        .delete("http://localhost:3000/posts/1")
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // http://localhost:3000/posts  可以做put请求
    testPut() {
      axios
        .put("http://localhost:3000/posts/1", {
          name: "lele",
        })
        .then((res) => {
          console.log(res);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>